package org.dromara.web.controller.business;

import jakarta.validation.constraints.*;
import org.dromara.web.domain.vo.RemoveRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.dao.business.domain.UserApiRecord;
import org.dromara.dao.business.domain.UserApiRecordQuery;
import org.dromara.web.service.business.UserApiRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.dromara.common.mybatis.core.page.TableDataInfo;


/**
 *  控制器
 *
 * @date 2025-04-17 14:49:14
 */
@Validated
@RestController
@RequestMapping("/user/userApiRecord")
public class UserApiRecordController extends BaseController {

    @Autowired
    private UserApiRecordService userApiRecordService;

    /**
     * 查询列表
     * @SaCheckPermission("user:userApiRecord:list")
     */

    @GetMapping("/list")
    public TableDataInfo<UserApiRecord> list(UserApiRecordQuery query, PageQuery pageQuery) {
        return userApiRecordService.queryPageList(query, pageQuery);
    }




    /**
     * 获取详细信息
     *
     * @param id 主键
     * @SaCheckPermission("user:userApiRecord:query")
     */
    @GetMapping("/info")
    public R<UserApiRecord> getInfo(@NotNull(message = "主键不能为空")
                                     @RequestParam Long id) {
        return R.ok(userApiRecordService.queryById(id));
    }

    /**
     * 新增
     * @SaCheckPermission("user:userApiRecord}:add")
     */

    @Log(title = "", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add( @RequestBody UserApiRecord entity) {
        userApiRecordService.insert(entity);
        return R.ok();
    }

    /**
     * 修改
     * @SaCheckPermission("user:userApiRecord:edit")
     */

    @Log(title = "", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/update")
    public R<Void> edit( @RequestBody UserApiRecord update) {
        userApiRecordService.updateById(update);
        return R.ok();
    }

    /**
     * 删除
     *
     * @param req 主键串
     * @SaCheckPermission("user:userApiRecord:remove")
     */

    @Log(title = "", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public R<Void> remove(@RequestBody RemoveRequest req) {
        userApiRecordService.deleteByIds(req.getIds());
        return R.ok();
    }
}
